import permissionService from "../serivce/permissionService";
import router from "@/router";
import dongRouter from "@/router/dongRouter";
export default {
  async userLogin({ commit }, { username, password }) {//登录
    // console.log(username, password);
    try {
      let result = await permissionService.UserLogin(username, password);
      console.log(router);
      if (result.data.code === 200) {
        commit("SetToken", result.data.data.token);
        commit("SetUserMenu", result.data.data.menuList);
        commit("SetUser", result.data.data.user);
        // 动态添加路由
        dongRouter.DynamicAddRouter();
        //设置是否刷新
        sessionStorage.setItem("IsRefresh", true);
       ;
        // 跳转到home组件
        router.push("/home");
      }
      return result.data;
    } catch (error) {
      console.log(error);
    }
  },
};
